package com.company.project.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.company.project.common.aop.annotation.LogAnnotation;
import com.company.project.common.utils.Func;
import com.company.project.entity.*;
import com.company.project.service.HttpSessionService;
import com.company.project.service.RoleService;
import com.company.project.service.UserService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import com.company.project.common.utils.DataResult;

import com.company.project.service.THwtjService;

import javax.annotation.Resource;


/**
 * 
 *
 * @author wenbin
 * @email *****@mail.com
 * @date 2023-11-01 18:51:05
 */
@Controller
@RequestMapping("/")
public class THwtjController {
    @Resource
    private THwtjService tHwtjService;

    @Resource
    private HttpSessionService httpSessionService;

    @Resource
    private UserService userService;


    @Resource
    private RoleService roleService;


    /**
    * 跳转到页面
    */
    @GetMapping("/index/tHwtj")
    public String tHwtj() {
        return "thwtj/list";
        }

    @ApiOperation(value = "新增")
    @PostMapping("tHwtj/add")
    @RequiresPermissions("tHwtj:add")
    @ResponseBody
    public DataResult add(@RequestBody THwtjEntity tHwtj){
        tHwtjService.save(tHwtj);
        return DataResult.success();
    }

    @ApiOperation(value = "删除")
    @DeleteMapping("tHwtj/delete")
    @RequiresPermissions("tHwtj:delete")
    @ResponseBody
    public DataResult delete(@RequestBody @ApiParam(value = "id集合") List<String> ids){
        tHwtjService.removeByIds(ids);
        return DataResult.success();
    }

    @ApiOperation(value = "更新")
    @PutMapping("tHwtj/update")
    @RequiresPermissions("tHwtj:update")
    @ResponseBody
    public DataResult update(@RequestBody THwtjEntity tHwtj){
        tHwtjService.updateById(tHwtj);
        return DataResult.success();
    }

    @ApiOperation(value = "查询分页数据")
    @PostMapping("tHwtj/listByPage")
    @LogAnnotation(title = "话务统计", action = "查询分页数据")
    @ResponseBody
    public DataResult findListByPage(@RequestBody THwtjEntity tHwtj){
        Page page = new Page(tHwtj.getPage(), tHwtj.getLimit());
        LambdaQueryWrapper<THwtjEntity> queryWrapper = Wrappers.lambdaQuery();
        //查询条件示例
        //queryWrapper.eq(THwtjEntity::getId, tHwtj.getId());
        //IPage<THwtjEntity> iPage = tHwtjService.page(page, queryWrapper);
        return tHwtjService.getPageList(page, tHwtj);
    }
    @ApiOperation(value = "查询初始化选项")
    @GetMapping("tHwtj/infoData")
    @LogAnnotation(title = "话务统计", action = "查询初始化选项")
    //@RequiresPermissions("tHwtj:list")
    @ResponseBody
    public DataResult infoData(){
        return tHwtjService.infoData();
    }
}
